<?php
namespace app\index\controller;

use \think\Session;
use \think\Controller;
use app\index\controller\Menu;
use app\index\controller\Customerc;
use app\index\model\Customer;
use app\index\model\Mail;
use app\index\model\Income;
use app\index\model\Copartner;
use app\index\model\Operation;
class Index extends Base
{
	public function index()
    {//312563
        $user["nik"] = Session::get("user_nik");
        $user["role"] = Session::get("user_role");
        $menus = new Menu();
        $user["menu"] = $menus -> get_menu($user["role"]);
        //$date = date("Y",time());
        $customer = new Customer();
        $data['customer_total'] = $customer -> customer_total();
        $data['customer_level'] = $customer -> customer_level();
        $data['customer_lose'] = $customer -> customer_lose();
        $data['customer_amount_total'] = $customer -> customer_amount_total();
        $data['customer_scores_consumption_total'] = $customer -> customer_scores_consumption_total();

        $this -> assign("user", $user);
        $this -> assign("data", $data);
        //$this -> view -> engine -> layout(true);
    	return $this -> fetch("index");
    }
    
    // 流水查询
    public function account_flow()
    {
        return $this -> fetch("account_flow");
    }
    // 用户列表
    public function account_list()
    {
        $this -> assign("url", "index/customerc/account");// 数据接口
        return $this -> fetch("account_list");
    }
    
    // 通道维护
    public function channel($value='')
    {
        //获取通道状态
        $operation = new Operation();
        $data = $operation -> get_channel();
        $status = [];
        $status["channel"] = 1;//所有通道，默认为已开启
        if($data["status"]==1){
            foreach($data["data"] as $key => $value){
                $status["channel"] = $status["channel"] && $value["status"];//修正总开关状态
                $status[$value["code"]] = $value["status"];
            }
        }

        $this -> assign("status",$status);
        return $this -> fetch("channel");
    }
    
    // 人工充值
    public function recharge_artifical($value='')
    {
        $worker = Session::get("user_id");
        $this -> assign("worker", $worker);
        return $this -> fetch("recharge_artifical");
    }
    // 发布公告
    public function notice($value='')
    {
        $worker = Session::get("user_id");
        $this -> assign("worker", $worker);
        return $this -> fetch("notice");
    }
    


    /*----------------*/
    public function baseinfo()
    {
        $user["name"] = Session::get("user_name");
        $user["nik"] = Session::get("user_nik");
        $user["role"] = Session::get("user_role");
        $this -> assign("user", $user);
        return $this -> fetch("baseinfo");
    }

    public function safecenter()
    {
        $worker = Session::get("user_name");
        $this -> assign("worker", $worker);
        return $this -> fetch("safecenter");
    }

    public function worker_list()
    {
        $this -> assign("url", "index/workerc/worker_list");// 数据接口
        return $this -> fetch("worker_list");
    }

    public function worker_create()
    {
        return $this -> fetch("worker_create");
    }

//-----------
    // 充值记录
    public function recharge_platform_list()
    {
        $customer = new Customer();
        $recharge_total = $customer -> recharge_group_total('n');
        $data['amount'] = $recharge_total["data"]["amount"];
        $this -> assign("data", $data);
        $this -> assign("url", "index/customerc/recharge_group_list");// 数据接口
        return $this -> fetch("recharge_platform_list");
    }
    public function recharge_artifical_list()
    {
        $customer = new Customer();
        $recharge_total = $customer -> recharge_group_total('x');
        $data['amount'] = $recharge_total["data"]["amount"];
        $this -> assign("data", $data);
        $this -> assign("url", "index/customerc/recharge_group_list");// 数据接口
        return $this -> fetch("recharge_artifical_list");
    }
    // 提现记录
    public function cash_list()
    {
        $customer = new Customer();
        $res_amount = $customer -> cash_total();
        $data['amount'] = $res_amount["data"]["amount"];
        $this -> assign("data", $data);
        $this -> assign("url", "index/Customerc/cash_list");// 数据接口
        return $this -> fetch("cash_list");
    }
//-----------Dev--------------
    // 
    public function hello()
    {
        return $this -> fetch("hello");
    }
    public function send()
    {
    	return $this -> fetch("send");
    }
}
